<<<<<<< HEAD
package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.PermissionDao;
=======
package com.itheima.health.service.impl;/*
 *@date:created in 2019/7/29
 *@description
 *@version:1.0
 */

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.PermissionDao;
import com.itheima.health.entity.PageResult;
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

<<<<<<< HEAD
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author:hujunwei
 * @Description:权限业务实现类
 * @Date:2019/7/29
 * @Version:1.0
=======
import java.util.List;
/**
 * @author ：ren
 * @date ：Created in 2019/7/30
 * @description ：权限实现类
 * @version: 1.0
>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
 */
@Service
@Slf4j
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;
<<<<<<< HEAD
    /*
     * @Author:hujunwei
     * @功能:查询权限列表，用于页面权限信息列表展示
     * @date: 2019/7/29
     * @param
     * @return java.util.List<com.itheima.health.service.Permission>
     */
    @Override
    public List<Permission> findAll() {
    List<Permission> permissions  =  permissionDao.findAll();
        return permissions;
    }

    /*
     * @Author:hujunwei
     * @功能:新增角色时，绑定了相应的权限，所以要增加角色和权限的中间表
     * @date: 2019/7/29
     * @param map
     * @return void
     */
    @Override
    public void addRoleAndPermission(Map<String, Integer> map) {
        permissionDao.addRoleAndPermission(map);
    }

    /*
     * @Author:hujunwei
     * @功能:通过角色id，查询所有与之对应的权限ids
     * @date: 2019/7/30
     * @param roleId
     * @return java.lang.Integer[]
     */
    @Override
    public List<Integer> findPermissionByRoleId(Integer roleId) {
        Set<Permission> permissions = permissionDao.findByRoleId(roleId);
        List<Integer> permissionIds=null;
        permissionIds = new ArrayList<>();//这个不能放在下面的for循环中，不然只会返回一个数据
        for (Permission permission : permissions) {
            permissionIds.add(permission.getId());
        }
        return permissionIds;
    }
=======
    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        // 使用分页插件PageHelper
        PageHelper.startPage(currentPage,pageSize);
        // 获取分页数据
        Page<Permission> permissions = permissionDao.selectByCondition(queryString);
        // 封装分页返回对象
        return new PageResult(permissions.getTotal(),permissions.getResult());
    }
//添加权限
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }
//修改权限
    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }
//根据id查权限
    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }
//删除权限
    @Override
    public void delete(Integer id) {
        permissionDao.deleteById(id);
    }


>>>>>>> 6693e98994950fffdaffe5b5f8491e5db91a2da2
}
